//
//  AppController.m
//  iTunesToTwitter
//
//  Created by Benjamin Ruoff on 12.05.09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "AppController.h"
@implementation AppController

- (IBAction)startStopUpdateBt:(id)sender
{
	[self updateTextFieldWithTrack];
}

- (IBAction)saveTwitterLogin:(id)sender
{
	[self saveCredentials];
}

- (void)saveCredentials
{
	DataStore* dataStore = [DataStore instance];
	
	if([@"" caseInsensitiveCompare:[login stringValue]] == NSOrderedSame || [@"" caseInsensitiveCompare:[password stringValue]] == NSOrderedSame )
	{
		NSAlert* alert = [[NSAlert alloc] init] ;
		[alert setMessageText: @"Wichtige Mitteilung"];
		[alert setInformativeText: @"Bitte vervollständigen Sie ihre Eingabe"];
		[alert setAlertStyle:NSInformationalAlertStyle];
		[alert runModal];
		[alert release]; 
	}
    else
	{
		[dataStore setLogin:[login stringValue]];
		[dataStore setPassword:[password stringValue]];
		NSAlert* alert = [[NSAlert alloc] init] ;
		[alert setMessageText: @"Mitteilung"];
		[alert setInformativeText: @"Zugangsdaten erfolgreich eingetragen"];
		[alert setAlertStyle:NSInformationalAlertStyle];
		[alert runModal];
		[alert release]; 	
	} 
}


- (void)updateTextFieldWithTrack
{
	DataStore* dataStore = [DataStore instance];
		
	if ([dataStore getUpdateStatus] != 0)
	{
		//Update Twitter Status with actual iTunes Track
		[dataStore setUpdateStatus:0];
		[startStopUpdateButton setTitle:@"Start Updating"];
	}
	else
	{
		//Check Credentials
		if([@"" caseInsensitiveCompare:[login stringValue]] == NSOrderedSame || [@"" caseInsensitiveCompare:[password stringValue]] == NSOrderedSame )
		{
			NSAlert* alert = [[NSAlert alloc] init] ;
			[alert setMessageText: @"Wichtige Mitteilung"];
			[alert setInformativeText: @"Bitte tragen Sie zuerst Ihre Zugangsdaten ein!"];
			[alert setAlertStyle:NSInformationalAlertStyle];
			[alert runModal];
			[alert release]; 
		}
		else
		{
			//Stop updating Twitter
			[dataStore setUpdateStatus:1];
			[startStopUpdateButton setTitle:@"Stop Updating"];
		}
		
	}
}

@end
